#!/usr/bin/env python3
#-*- coding:utf-8 -*-
#
# arvoredenatal.py
# This file is part of ifnatal
#
# Copyright (C) 2012 - Jurandy Soares
#
# ifnatal is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# ifnatal is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ifnatal; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, 
# Boston, MA  02110-1301  USA
#

import turtle
import sys

DIST = 22
SUSP = 180

def criar_pincel(forma, cor):
    pincel = turtle.Turtle()
    pincel.shape(forma)
    pincel.color(cor)
    pincel.up()    
    return pincel
    
def desenhar_simetria_bilateral(pincel, cord_x, cord_y):
    pincel.goto(cord_x, -cord_y+SUSP)
    pincel.stamp()
    pincel.goto(-cord_x, -cord_y+SUSP)
    pincel.stamp()

def main():
    tela = turtle.Screen()
    tela.setup(1024,768)
    tela.title('Árvore de Natal / Módulo IFNATAL / Pacote IFJOGO')

    circulo = criar_pincel('circle', 'red')
    quadrado = criar_pincel('square', 'green')
    
    circulo.goto(0,SUSP)
    circulo.stamp()

    # Controla as cavidades na copa da árvore
    k = 0
    
    # Quantidade de linhas de folhas da árvore
    for i in range(1, 17):
        y = DIST*i
        
        # Desenha uma linha de folhas
        for j in range(i-k):
            x = DIST*j
            desenhar_simetria_bilateral(quadrado, x, y)

        # Desenha bolas vermelhas nas extremidades da linha, a cada 4 linhas
        if i % 4 == 0:
            x =  DIST*(j+1)
            desenhar_simetria_bilateral(circulo, x, y)
            k += 2

    # Desenha o tronco
    quadrado.color('brown')
    for i in range(17,21):
        y = DIST*i
        for j in range(3):    
            x = DIST*j
            desenhar_simetria_bilateral(quadrado, x, y)
            
    turtle.exitonclick()

if __name__ == '__main__':
    sys.exit(main())

